<?php
/**
 * @author Radovan Dvorsky
 * @version 20100227
 */
require_once ('library/My/Form/AjaxForm.php');

class Form_Block_AddGroup extends My_Form_AjaxForm {
	
	private $_groups;
	
	public function init(){
		
		$cache = Zend_Registry::get('cache');
		$cacheName = My_Support::getCacheName('groups','fetchAll');
		
		if(!($this->_groups = $cache->load($cacheName))){
			$tridyMapper = new Db_Mapper_TTridy();
			$this->_groups = $tridyMapper->fetchAll();
			$cache->save($this->_groups,$cacheName);			
		}		
	}
	
	function __construct($url, $update, $format = 'html',$options = null) {
		parent::__construct($options);
		
		$this->setMethod('post');
		
		$this->setJqueryParams(array(
				'url' => $url,
				'update' => $update,
				'format' => $format,
				'append' => true			
			)			
		);
		
		$groups = new Zend_Form_Element_Select('ID_tr');
		$groups->setDecorators(array('ViewHelper'));	
		
		foreach($this->_groups as $group){
			$groups->addMultiOption($group->ID_tr,$group->Zkratka);
		}
		
		$submit = new Zend_Form_Element_Button('submitGroups');
		$submit->setDecorators(array('ViewHelper'))
		->setLabel('Pridať');
		
		$bid = new Zend_Form_Element_Hidden('bid');
		$bid->setDecorators(array('ViewHelper'));
		
		$this->addAjaxableElements(array($groups,$bid));
		$this->setSender($submit,'onClick');
		
		$this->addElements(array($groups,$bid,$submit));
	}
}

?>